package com.dycloud.project.controller;

import com.dycloud.project.request.ReviewIndustryRequest;
import com.dycloud.project.aspectj.lang.annotation.Log;
import com.dycloud.project.aspectj.lang.enums.BusinessType;
import com.dycloud.project.web.controller.BaseController;
import com.dycloud.project.web.domain.AjaxResult;
import com.dycloud.project.web.page.TableDataInfo;
import com.dycloud.project.domain.IndustryTrends;
import com.dycloud.project.service.IIndustryTrendsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author : renhang
 * @description IndustryTrendsController
 * @date : 2025-07-02 18:45
 **/

@RestController
@RequestMapping("/business/trends")
public class IndustryTrendsController extends BaseController {
    @Autowired
    private IIndustryTrendsService industryTrendsService;

    /**
     * 查询行业动态新闻列表
     */
    @PreAuthorize("@ss.hasPermi('business:trends:list')")
    @GetMapping("/list")
    public TableDataInfo list(IndustryTrends industryTrends) {
        startPage();
        return industryTrendsService.selectIndustryTrendsList(industryTrends);
    }


    /**
     * 获取行业动态新闻详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:trends:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(industryTrendsService.selectIndustryTrendsById(id));
    }

    /**
     * 新增行业动态新闻
     */
    @PreAuthorize("@ss.hasPermi('business:trends:add')")
    @Log(title = "行业动态新闻", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndustryTrends industryTrends) {
        return toAjax(industryTrendsService.insertIndustryTrends(industryTrends));
    }

    /**
     * 修改行业动态新闻
     */
    @PreAuthorize("@ss.hasPermi('business:trends:edit')")
    @Log(title = "行业动态新闻", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndustryTrends industryTrends) {
        return toAjax(industryTrendsService.updateIndustryTrends(industryTrends));
    }

    /**
     * 删除行业动态新闻
     */
    @PreAuthorize("@ss.hasPermi('business:trends:remove')")
    @Log(title = "行业动态新闻", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(industryTrendsService.deleteIndustryTrendsByIds(ids));
    }


    /**
     * 管理员审核
     *
     * @param request request
     * @return
     */
    @PreAuthorize("@ss.hasRole('admin')")
    @Log(title = "行业动态新闻审核", businessType = BusinessType.REVIEW)
    @PutMapping("review")
    public AjaxResult review(@RequestBody @Validated ReviewIndustryRequest request) {
        industryTrendsService.review(request);
        return AjaxResult.success();
    }
}
